package com.kyk.controller;

import com.kyk.entity.Merchants;
import com.kyk.service.IMerchantsService;
import com.kyk.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 商家表 前端控制器
 * </p>
 *
 * @author 凯
 * @since 2025-09-12
 */
@RestController
@RequestMapping("/merchants")
public class MerchantsController {

    @Autowired
    IMerchantsService merchantsService;

     /**
     * 新增商家
     * @param merchants
     * @return
     */
    @PostMapping
    public Result addMerchants(@RequestBody Merchants merchants){
        return merchantsService.addMerchants(merchants);
    }

    /**
     * 登录
     * @param merchants
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Merchants merchants){
        return merchantsService.login(merchants);
    }

    @GetMapping("/current")
    public Result getCurrentUser(
            // 从请求头获取过滤器传递的用户ID和类型
            @RequestHeader("X-User-Id") Long merchantId,
            @RequestHeader("X-User-Type") String userType) {

        return merchantsService.getCurrentMerchant(merchantId, userType);
    }


}
